package com.zrlh.file_trans_monitor.task;

import com.zrlh.file_trans_monitor.service.FileMonitorService;
import com.zrlh.file_trans_monitor.util.HttpRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@EnableScheduling
@Component
@Slf4j
public class FileTransTask {
    @Autowired
    private FileMonitorService fileMonitorService;
    @Value("${falcon.agent.url}")
    private String url;
    @Value("${sendMessageToFalcon.open}")
    private boolean open;
    //每30分钟读取一次CSV
    @Scheduled(cron = "45 0/30 * * * ?")
    public void initTask(){
        fileMonitorService.initTask();
    }
    //每分钟的第5秒执行一次
    @Scheduled(cron = "5 * * * * ?")
    public void runTask(){
        if(open){
            HttpRequest.httpPostWithjson(url, fileMonitorService.getMessage());
        }
        else
            fileMonitorService.monitor();
    }
    //每日0点清理一次任务异常列表
    @Scheduled(cron = "0 0 0 * * ?")
    public void cleanExceptionList(){
        fileMonitorService.cleanERRORList();
    }
}
